<?php
namespace app\manage\controller;
use think\Db;
use think\helper\Time;

class Index extends Base
{
    private $db;
    public function _initialize()
    {
        parent::_initialize();
    }

    public function index()
    {

        $info = [];
        $defMsg=model('MsgNotice')->where('role_type',2)->where('msg_type',3)->where('status',0)->find();
        $youMsg=[];
        return $this->fetch('',['info'=>$info,'defMsg'=>$defMsg,'youMsg'=>$youMsg]);
    }


    public function error1()
    {
        return $this->fetch();
    }


    public function edit_password()
    {
        // 查询条件start
        $uid = $this->uid;

        $admin = model('Admin')->getInfoByMap(['id'=>$uid]);

        return $this->fetch('',[
            'admin' => $admin,
        ]);
    }


    public function save_password()
    {
        if(request()->isAjax()){

            try{
                $password = input('post.password');
                $id = input('post.id');

                if(isset($id) && $id){
                    $save_data['id'] = $id;
                    if(!empty($password)){
                        $save_data['salt'] = $this->builderRand(4);
                        $save_data['password'] = md5(input('post.password') . $save_data['salt']);

                        $result = $this->editData(false,'','Admin',$save_data);

                        if($result['code'] == 1001){
                            $result['msg'] = '修改密码成功';
                            $this->RecordSystemLog($this->uid,$this->behavior,'修改密码成功');
                        }

                        return $result;
                    }else{
                        return self::showReturnCode(1003,'密码为空');
                    }
                }else{
                    return self::showReturnCode(1002,'参数错误');
                }

            }catch (\Exception $e){
                return self::showReturnCode(1011,$e->getMessage());
            }
        }else{
            return self::showReturnCode(1002);
        }
    }



}